#include "output.h"

void output_hexahedron() {
	FILE* FileNO_OUTPUT;
	int N = MAP_DATA.SPECGRID.NX * MAP_DATA.SPECGRID.NY * MAP_DATA.SPECGRID.NZ;

	FileNO_OUTPUT = fopen("hexahedron.vtk", "w");
	if (FileNO_OUTPUT == NULL) {
		printf("FileNO_OUTPUT.txt create error!\n");
		exit(-1);
	}

	fprintf(FileNO_OUTPUT, "%s\n","# vtk DataFile Version 2.0");
	fprintf(FileNO_OUTPUT, "%s\n", "QUESTION3");
	fprintf(FileNO_OUTPUT, "%s\n", "ASCII");
	fprintf(FileNO_OUTPUT, "%s\n", "DATASET UNSTRUCTURED_GRID");
	fprintf(FileNO_OUTPUT, "\n");
	fprintf(FileNO_OUTPUT, "POINTS %d float\n", DATA_NUM);

	for (int i = 0; i < DATA_NUM; ++i) {
		fprintf(FileNO_OUTPUT, "%lf ", DATA[i].COORD_DATA.X);
		fprintf(FileNO_OUTPUT, "%lf ", DATA[i].COORD_DATA.Y);
		fprintf(FileNO_OUTPUT, "%lf\n", DATA[i].COORD_DATA.Z);
	}

	fprintf(FileNO_OUTPUT, "\n");
	fprintf(FileNO_OUTPUT, "CELLS %d %d\n", UNIT_NUM, UNIT_NUM * 9);
	for (int i = 0;i < N;++i) {
		fprintf(FileNO_OUTPUT, "8 %d %d %d %d %d %d %d %d\n", UNIT[i].CORNER_POINT[0], UNIT[i].CORNER_POINT[1], UNIT[i].CORNER_POINT[3],
			UNIT[i].CORNER_POINT[2], UNIT[i].CORNER_POINT[4], UNIT[i].CORNER_POINT[5], UNIT[i].CORNER_POINT[7], UNIT[i].CORNER_POINT[6]);
	}
	fprintf(FileNO_OUTPUT, "\n");
	fprintf(FileNO_OUTPUT, "CELL_TYPES %d\n", UNIT_NUM);
	for (int i = 0;i < UNIT_NUM;++i) {
		fprintf(FileNO_OUTPUT, "%d\n", 12);
	}

	fprintf(FileNO_OUTPUT, "\n");
	fprintf(FileNO_OUTPUT, "CELL_DATA %d\n", N);
	fprintf(FileNO_OUTPUT, "SCALARS YOUNGMOD float 1\n");
	fprintf(FileNO_OUTPUT, "LOOKUP_TABLE default\n");
	for (int i = 0;i < N ;++i) {
		fprintf(FileNO_OUTPUT, "%.10lf\n", MAP_DATA.YOUNGMOD[i]);
	}

	fprintf(FileNO_OUTPUT, "\n");
	fprintf(FileNO_OUTPUT, "CELL_DATA %d\n", N);
	fprintf(FileNO_OUTPUT, "SCALARS POISSONR float 1\n");
	fprintf(FileNO_OUTPUT, "LOOKUP_TABLE default\n");
	for (int i = 0;i < N;++i) {
		fprintf(FileNO_OUTPUT, "%.10lf\n", MAP_DATA.POISSONR[i]);
	}

	fprintf(FileNO_OUTPUT, "\n");
	fprintf(FileNO_OUTPUT, "CELL_DATA %d\n", N);
	fprintf(FileNO_OUTPUT, "SCALARS ROCKDEN float 1\n");
	fprintf(FileNO_OUTPUT, "LOOKUP_TABLE default\n");
	for (int i = 0;i < N;++i) {
		fprintf(FileNO_OUTPUT, "%.10lf\n", MAP_DATA.ROCKDEN[i]);
	}

	fprintf(FileNO_OUTPUT, "\n");
	fprintf(FileNO_OUTPUT, "CELL_DATA %d\n", N);
	fprintf(FileNO_OUTPUT, "SCALARS PORO float 1\n");
	fprintf(FileNO_OUTPUT, "LOOKUP_TABLE default\n");
	for (int i = 0;i < N;++i) {
		fprintf(FileNO_OUTPUT, "%.10lf\n", MAP_DATA.PORO[i]);
	}

	fclose(FileNO_OUTPUT);
}